home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / quotemkr / functins.c < prev    next >
Encoding:
Text File  |  1993-06-15  |  30.0 KB  |  866 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /*$Header: /Source/Media/collab/QuoteMaker/RCS/functions.c,v 2.15 92/09/25 14:31:50 drapeau Exp $*/
  25. /* $Log:    functions.c,v $
  26.  * Revision 2.15  92/09/25  14:31:50  drapeau
  27.  * Fixed errors in the way the quoted text window was being located.  The
  28.  * earlier version used the XView attributes "XV_WIDTH", "XV_HEIGHT", "XV_X",
  29.  * and "XV_Y".  This version now uses the more proper "frame_get_rect()" and
  30.  * "frame_set_rect()" functions for window placement and sizing.
  31.  * Also, some cosmetic changes were made to enhance readability and ANSI
  32.  * compliance.
  33.  * 
  34.  * Revision 2.14  92/06/15  14:33:51  drapeau
  35.  * Minor change, casted an xv_get() call to (char*) to avoid compiler
  36.  * warning message.
  37.  * 
  38.  * Revision 2.13  92/05/14  15:41:03  drapeau
  39.  * * Updated copyright information.
  40.  * * Other formatting changes to conform to coding standards.
  41.  * 
  42.  * Revision 2.12  92/01/11  01:43:09  drapeau
  43.  * Removed redeclarations of string functions since OpenWindows 2.0
  44.  * headers don't seem to like them (OpenWindows 3.0 seemed to need
  45.  * them).
  46.  * 
  47.  * Revision 2.11  92/01/09  18:25:19  drapeau
  48.  * Slight modifications to make code ANSI-compliant.
  49.  * 
  50.  * Revision 2.10  91/12/31  18:42:40  drapeau
  51.  * Removed the inclusion of string.h, since XView will include the
  52.  * appropriate definitions.
  53.  * 
  54.  * Revision 2.0  91/09/30  15:02:31  derek
  55.  * Version number changed to 2.0.
  56.  * 
  57.  * Revision 1.12  91/09/15  20:32:31  derek
  58.  * The function ShowPreviewFunctionsPanel() is removed.  Also, in 
  59.  * PreloadFontOntoQTW(), a statement is added to clear the quote window
  60.  * before loading fonts.
  61.  * 
  62.  * Revision 1.11  91/09/15  20:06:25  derek
  63.  * The following things are done:
  64.  * 1.      The foreground of mainTextPane and Quote Window are set to be black.
  65.  *         Also, the color of all the text fields are set to black.
  66.  * 2.      Now the quoted text will be shown directly on the Quote Window
  67.  *         when a panel-item selection is made.  The text will also be shown
  68.  *         while the author is highlighting a selection in the text window.
  69.  * 3.      The inconsistency problem regarding text selection is being taken
  70.  *         care of.  When the mouse cursor re-enters the text window,
  71.  *         the selection will be highlighted again.
  72.  * 4.      When the play button is pressed, the text currently selected
  73.  *         in the text window (rather than the text initially associated
  74.  *         with the edit) will be displayed.
  75.  * 5.      The name of the menu_option "Show Quote Window Specifications panel"
  76.  *         is shortened to be "Quote Window Options ..."
  77.  * 6.      A notify_interpose_destroy_func() is being added to fix the bug
  78.  *         that QuoteMaker might exit without killing the Quote Window (which
  79.  *         is also a base window).
  80.  * 7.      When a different font family or font style is selected, the change
  81.  *         will be automatically be reflected on the Quote Window (without the
  82.  *         need to "play" the edit in order to verify the font).  For font
  83.  *         size, the change will be reflected when either a return character is
  84.  *         entered at the text field or when one of those numeric "arrows"
  85.  *         are pressed.
  86.  * 8.      The play button will now flash when an edit is being played.
  87.  *         Pause button will also glow when playing is paused.
  88.  * 9.      In the course of playing, when another edit is selected,
  89.  *         the playing will be stopped.
  90.  * 10.     I have used Saber to clean up the code.
  91.  * 11.     The left-over "NewEditListPopUp" window is removed.
  92.  * 12.     The bug that when quote window is iconified, it wont be un-iconified
  93.  *         when the edit is played in timeline, is fixed.
  94.  * 13.     The DurationEstimate function is changed so that it no longer
  95.  *         needs an edit to be selected first.  It will take textWindowStart
  96.  *         and textWindowEnd directly as input parameters.
  97.  * 
  98.  * 
  99.  * 
  100.  * Revision 1.10  91/09/05  15:48:01  derek
  101.  * The following changes are made:
  102.  * 1.      The name "Quoted Text Window" has been changed to "Quote Window"
  103.  *         in the app.
  104.  * 2.      ShowApplication() and HideApplication() is changed because of the
  105.  *         the change of quote window from a popup to a basewindow.
  106.  * 3.      The QuitProc of QuoteMaker is fixed so that the quote window,
  107.  *         as a base window, will be destroyed separately.
  108.  * 4.      Now hitting return in the label field will not result in adding
  109.  *         a new edit.
  110.  * 5.      Copyright messages are included in front of every .h and .c file.
  111.  * 6.      The scrollbar and the footer of the Quote Window are hidden.
  112.  * 7.      I have changed the include openpanel.h statement in QuoteMaker.c
  113.  *         to include Browse.h.
  114.  * 8.      The delete bug corresponding to the change that the panel-list
  115.  *         must have a choice -- is fixed.  Also, the corresponding bug
  116.  *         for deleteAll is also fixed.
  117.  * 9.      Now, deleteAll and deletion of the last item in Panel_list
  118.  *         will cause the panel-list to be destroyed and a new one will
  119.  *         be created.
  120.  * 10.     GetOpt files have been removed from the directory.  Corresponding
  121.  *         changes are made.
  122.  * 11.     The start and end byte fields are removed from the main panel.
  123.  * 12.     I have put iconify, hide and show quote window to be buttons
  124.  *         instead of menu options.
  125.  * 13.     I have removed the PreviewPanelPopup and incorporated its features into
  126.  *         the main panel.  The three buttons:  pause, play and stop and
  127.  *         the DurationGauge are moved to the main panel.  But the
  128.  *         StatusMessage is removed.
  129.  * 14.     The EnableLocationChange and EnableSizeChange choice setting
  130.  *         are removed.  There are no longer such choices.
  131.  * 15.     Right now if a panel-item is selected and if another panel-item
  132.  *         is picked, the DeselectList() operation in the middle is
  133.  *         eliminated.  This operation involves updating of text fields and
  134.  *         messages and its removal speeds up the program.  The panel-list
  135.  *         must now take at least one choice.  (A choice must be selected
  136.  *         whenever there is at least one item on the list).  And now
  137.  *         there is no way to deselect a list by the user.
  138.  * 16.     The "modified bit" associated with the CurrentSelectionNumberLabel
  139.  *         is implemented.  Now, if a selection is picked, and if either
  140.  *         the quote window is moved or any text fields are changed, the
  141.  *         modified bit will be on.
  142.  * 17.     The Show-text-window button and the Show-quote-window-specifications-popup
  143.  *         button are removed.  They are now menu options under the Options Menu.
  144.  * 18.     The Modify button has its name changed to "Update Edit".
  145.  * 
  146.  * Revision 1.9  91/08/28  14:06:06  derek
  147.  * The following things are done:
  148.  * 1.    I have changed the NewEditList option to call the file browser
  149.  *     instead of giving a popup window.
  150.  * 2.    I ahve renamed all the options in the file menu so that they
  151.  *     are clearer and more informative.
  152.  * 3.    The documentFileType has been changed from "DTR" (which was
  153.  *     a copying fault :)) to "QuoteMaker".
  154.  * 4.    I ahve changed the stop button so that if it sees that 
  155.  *     HideQTWAfterPlayingEdit is true, stopplay will hide the window too.
  156.  * 5.    I have changed QuoteMaker.G (the interface) so that there is no
  157.  *     way to deselect a fontfamily and fontstyle item from the panel list
  158.  *     (ie. a choice is required.)
  159.  * 
  160.  * Revision 1.8  91/08/27  14:37:33  derek
  161.  * The following things are done:
  162.  * 1.    The QuotedTextWindow is changed from a base window to a popup window
  163.  *     (now it's called QuotedMaker_quotedTextBaseWindow).  I have also
  164.  *     added a few options: show, hide and iconify QTW and also created
  165.  *     an icon for QTW.
  166.  * 2.    The quoted text will be set in PerformSelection() instead of 
  167.  *     in SetSelection().
  168.  * 3.    I have changed the Document field and the EditList field of 
  169.  *     QuoteMaker so that they will display fill paths.
  170.  * 
  171.  * Revision 1.7  91/08/26  12:10:15  derek
  172.  * The following things are done:
  173.  * 1.    I have added a few notice_prompts to the linkProtocol (network)
  174.  *     functions to give warnings about invalid document names.
  175.  * 2.    The quoted text window will by default be hidden during "blank"
  176.  *     times. ie. when it is not displaying any text.  The interface has
  177.  *     been changed so that it now has a HideQuotedTExtWindowAfterPreview
  178.  *     check box.  The QuotedTextWindow will either stay on the screen
  179.  *     or be hidden as the author desires.
  180.  * 3.    Make the changes corresponding to the changing of name from OpenPanel
  181.  *     to Browse.
  182.  * 4.    The return value bug for OpenHandler, SaveHandler is fixed.
  183.  * 5.    I have changed the code so that Save and SaveAs will behave correctly.
  184.  *     The SaveAs PopUp/Open PopUp are removed.  Browse check is 
  185.  *     incorporated in the applications.
  186.  * 6.    The QuoteMaker file format has been changed.  An EditNumber field    
  187.  *     has been added.
  188.  * 7.    Changes corresponding to the return value by OpenDoc and SetSelection
  189.  *     are made.
  190.  * 8.    GetAppIcon() has been implemented.
  191.  * 9.    Fonts specified in the Edit-list will be preloaded in OpenDoc().
  192.  *     This will hopefully eliminate the startup delay needed to load
  193.  *     the font when we put text onto the Quoted TExt Window for the 
  194.  *     first time.
  195.  * 10.    The "play" button will now play things specified in the 
  196.  *     QuotedTExtWindowSpecificationsPopUp (instead of those specified
  197.  *     in the editList).
  198.  * 11.    The show selection button is replaced by the set selection button.
  199.  *     The Set Selection button willl now not only set the current
  200.  *     edit parameters but will also highlight the corresponding section
  201.  *     in the text.  Also, when one item on the panel-list is clicked on,
  202.  *     the corresponding segment in the text will also be highlighted.
  203.  * 12.    Notify events which tells the app to show the size and location 
  204.  *     of the Quoted Text Window are set up.  ie. those text-fields
  205.  *     on the interface will be updated instantaneously.
  206.  * 16.    editList.label is being sent across the network.
  207.  * 17.    The title bar and the footer of the QuotedTExtWindow are hidden.
  208.  * 
  209.  * Revision 1.6  91/07/22  16:46:56  derek
  210.  * I have added 4 buttons to get and set the current
  211.  * location and size of the quoted text window.
  212.  * 
  213.  * Revision 1.5  91/07/15  12:19:28  derek
  214.  * 1.      I have added font selection panel to the application.
  215.  *         Now a user can specify a font by choosing a font family, a font
  216.  *         style and font size.
  217.  * 2.      Location and size fields are added to the application.  User
  218.  *         can specify the size and location of the QuotedTextWindow.
  219.  * 3.      A duration estimate button is added to estimate how long the
  220.  *         the quoted text should last.
  221.  * 4.      Interface has been redesigned to accomodate the addition of
  222.  *         font, size and location functionalities.
  223.  * 6.      EditList file format has been changed to accomodate the new
  224.  *         fields.  They are:  location (x,y), width, height, font family,
  225.  *         font style, font width for QuotedTextWindow.
  226.  * 5.      Two timers have been added in an attempt to ensure accuracy
  227.  *         of gauge-updating in the preview panel.
  228.  * 6.      Command line args are now supported.
  229.  * 7.      I have cleaned up the code by using saber.
  230.  * 8.      Several bugs from previous revision are fixed.
  231.  * 
  232.  * 
  233.  * Revision 1.4  91/07/02  15:07:51  derek
  234.  * QuoteMaker now fully speaks the new MAEstro protocol.
  235.  * 
  236.  * Revision 1.3  91/07/01  19:09:22  derek
  237.  * The following things are done:
  238.  * 1.    The interface is redesigned.  Duration fields are added to each
  239.  *     edit list.
  240.  * 2.    The function panel (functions Window) is implemented.  The
  241.  *     application is now capable of being "played", "stopped"
  242.  *     and "Paused".  The sense of "time" is now complete.
  243.  * 3.    Makefile fixed.
  244.  * 4.    Declaration errors left by previous author are cleaned up.
  245.  * 5.    Redundant malloc statements removed.  Certain other
  246.  *     functions are changed to improve code efficiency.
  247.  * 6.    Code cleaned up by saber.  Removed redundant variables.
  248.  *  */
  249.  
  250. static char rcsid[] = "$Header: /Source/Media/collab/QuoteMaker/RCS/functions.c,v 2.15 92/09/25 14:31:50 drapeau Exp $";
  251.  
  252. #include <stdio.h>
  253. #include <sys/param.h>
  254. #include <sys/types.h>
  255. #include <xview/xview.h>
  256. #include <xview/panel.h>
  257. #include <xview/textsw.h>
  258. #include <xview/xv_xrect.h>
  259. #include <gdd.h>
  260. #include "QuoteMaker_ui.h"
  261. #include <sys/stat.h>
  262. #include <xview/font.h>
  263. #include <xview/notice.h>
  264. #include <xview/notify.h>
  265. #include <xview/server.h>          
  266. #include <xview/seln.h>            
  267. #include <xview/scrollbar.h>
  268. #include "quoteMakerDefs.h"
  269. #include <math.h>
  270.  
  271.  
  272. void
  273.   InitTextFields()
  274. {
  275.   xv_set(QuoteMaker_baseWindow->DurationMinsTextField,
  276.      PANEL_NOTIFY_LEVEL, PANEL_ALL, NULL);
  277.   xv_set(QuoteMaker_baseWindow->DurationSecsTextField,
  278.      PANEL_NOTIFY_LEVEL, PANEL_ALL, NULL);
  279.   xv_set(QuoteMaker_baseWindow->selectionLabelField,
  280.      PANEL_NOTIFY_LEVEL, PANEL_ALL, NULL);
  281.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontSizeTextField,
  282.      PANEL_NOTIFY_LEVEL, PANEL_ALL, NULL);
  283. }  
  284.  
  285.  
  286. /*
  287.  * Notify callback function for `PauseButton'.
  288.  */
  289. void
  290. PauseButtonHandler(item, event)
  291.     Panel_item    item;
  292.     Event        *event;
  293. {
  294.   extern  double  endTime;
  295.   
  296.   if (Playing)
  297.   {
  298.     if (PlayPaused) 
  299.     {
  300.       PlayPaused = FALSE;
  301.       SetTimer(endTime);
  302.       xv_set(QuoteMaker_baseWindow->PauseButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  303.       AlertStatus("Playing ...");
  304.     }
  305.     else
  306.     {
  307.       PlayPaused = TRUE;
  308.       CancelTimer();
  309.       xv_set(QuoteMaker_baseWindow->PauseButton, PANEL_ITEM_COLOR, GreenColorIndex, NULL);
  310.       xv_set(QuoteMaker_baseWindow->PlayButton, PANEL_ITEM_COLOR, GreenColorIndex, NULL);
  311.     }
  312.   }
  313.   textsw_set_selection(QuoteMaker_textWindowPopup->mainTextPane,    /*  Highlight the selection (because the text_sw... */
  314.                textWindowStart, textWindowEnd + 1,        /*  ...will keep forgetting about it.               */
  315.                PRIMARY_SELECTION);
  316. }
  317.  
  318.  
  319. /*
  320.  * Notify callback function for `StopButton'.
  321.  */
  322. void
  323. StopButtonHandler(item, event)
  324.     Panel_item    item;
  325.     Event        *event;
  326. {
  327.   CancelTimer();
  328.   ClearStatusMessage();
  329.   ClearQuotedTextWindow();
  330.   if (HideQTWAfterPlayingEdit)
  331.   {
  332.     xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  333.        XV_SHOW, FALSE,
  334.        NULL);
  335.   }    
  336.  
  337.   if (Playing)
  338.   {
  339.     CancelButtonGlowTimer();
  340.     CancelButtonGlow();
  341.   }
  342.  
  343.   PlayPaused = FALSE;
  344.   Playing = FALSE;
  345.  
  346.   textsw_set_selection(QuoteMaker_textWindowPopup->mainTextPane,    /*  Highlight the selection (because the text_sw... */
  347.                textWindowStart, textWindowEnd + 1,        /*  ...will keep forgetting about it.               */
  348.                PRIMARY_SELECTION);
  349. }
  350.  
  351.  
  352. /*
  353.  * Notify callback function for `PlayButton'.
  354.  */
  355. void
  356. PlayButtonHandler(item, event)
  357.     Panel_item    item;
  358.     Event        *event;
  359. {
  360.   int        entryNum;
  361.   int        length;
  362.   int        count;
  363.   int       mins;
  364.   double    secs;
  365.   double    duration;
  366.   char*        selectedText;
  367.   char*        tempPointer;
  368.   char*        index();
  369.   
  370.   if (Playing)                                /* If and edit is being played right now, do....    */
  371.     return;                                /* ...nothing.                                      */
  372.  
  373.   entryNum = Selected();
  374.  
  375.   if (entryNum == NO_CURRENT_EDIT)
  376.     return;
  377.   
  378.   if (entryNum >= editList.numItems)                    /* Check for selection requested not on edit list...*/
  379.     return;                                /* ...ie. edit list has 5 items and request is... */
  380.   /* ...for item # 9 */
  381.  
  382.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  383.      FRAME_CLOSED, FALSE,
  384.      XV_SHOW, TRUE,
  385.      NULL);
  386.  
  387.   length=xv_get(QuoteMaker_quotedTextBaseWindow->quotedTextPane,    /* Get the number of characters currently in the... */
  388.         TEXTSW_LENGTH);                        /* ...popup win. */
  389.   if (length > 0)
  390.   {
  391.     textsw_delete(QuoteMaker_quotedTextBaseWindow->quotedTextPane,  /* Erase any previously shown text in the Text... */
  392.           0, length);                        /* popup window. */
  393.     textsw_reset(QuoteMaker_quotedTextBaseWindow->quotedTextPane,0,0); /* Pretend that the QTW was never modified */
  394.   }
  395.   
  396.   length = textWindowEnd - textWindowStart + 1;                /* Calculate size of text to be selected */
  397.   selectedText = (char *) malloc(length + 1);                /* Allocate space for the text to be selected */
  398.   xv_get(QuoteMaker_textWindowPopup->mainTextPane,            /* Get the text to be selected */
  399.      TEXTSW_CONTENTS, textWindowStart, selectedText, length);
  400.   selectedText[length] = '\0';                        /* Make sure selected text is NULL-terminated */
  401.   for (tempPointer = selectedText, count=0;                /* Go through selected text, looking for newlines... */
  402.        tempPointer;                            /* ...and replace each newline with a space. */
  403.        tempPointer = index(tempPointer, '\n'), count++)
  404.   {
  405.     if (tempPointer != selectedText)                    /* Is "tempPointer" pointing to start of the buffer? */
  406.       tempPointer[0] = ' ';                        /* No, must be pointing to a newline; replace it... */
  407.     /* ...with space. */
  408.     if (count > 100)                            /* If this loop has replaced a large number of ... */
  409.       break;                                /* ...lines, exit loop; chances are the end... */
  410.     /* ...won't be saved anyway. */
  411.   }
  412.   
  413.   currentFontSize = xv_get(QuoteMaker_QuoteWindowSpecificationsPopup->FontSizeTextField,
  414.                PANEL_VALUE);
  415.  
  416.   SetQuotedTextWindowFont(currentFontFamily,
  417.               currentFontStyle,
  418.               currentFontSize);
  419.  
  420.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Allow the Quoted Text popup window to be edited */
  421.      TEXTSW_BROWSING, FALSE, NULL);
  422.  
  423.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Put the selected text into the quoted Text... */
  424.      TEXTSW_CONTENTS, selectedText, NULL);                /* ...popup window */
  425.  
  426.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Allow the Quoted Text popup window to be edited */
  427.      TEXTSW_BROWSING, TRUE, NULL);
  428.   
  429.   textsw_normalize_view(QuoteMaker_quotedTextBaseWindow->quotedTextPane,
  430.             0);                        /* Make sure quoted text shows up at top of... */
  431.   /* ...popup window. */
  432.  
  433.   InitTimer();
  434.  
  435.   Playing = TRUE;
  436.   AlertStatus("Playing ...");
  437.   mins = (int) atoi(xv_get (QuoteMaker_baseWindow->DurationMinsTextField, PANEL_VALUE));
  438.   secs = (double) atof((char*)xv_get(QuoteMaker_baseWindow->DurationSecsTextField, PANEL_VALUE));
  439.   duration = mins * 60.0 + secs;
  440.  
  441.   textsw_set_selection(QuoteMaker_textWindowPopup->mainTextPane,    /*  Highlight the selection (because the text_sw... */
  442.                textWindowStart, textWindowEnd + 1,        /*  ...will keep forgetting about it.               */
  443.                PRIMARY_SELECTION);
  444.  
  445.   SetButtonGlowTimer(GLOW_INTERVAL);
  446.   SetTimer(duration);
  447. }
  448.  
  449.  
  450. void
  451.   AlertStatus(message)
  452. char  *message;
  453. {
  454.   char m[40];
  455.   
  456.   sprintf(m, "Status :   %s", message);
  457.   
  458. /********
  459.   xv_set(QuoteMaker_PreviewPanelPopup->PreviewPanelStatusMessage,
  460.      PANEL_LABEL_STRING, m, NULL);
  461.   XFlush((Display *) xv_get(QuoteMaker_PreviewPanelPopup->PreviewPanelPopup, 
  462.                 XV_DISPLAY));
  463. ********/
  464. }
  465.  
  466.  
  467. void
  468.   ClearStatusMessage()
  469. {
  470.   AlertStatus("");
  471. }
  472.  
  473.  
  474. void
  475.   ClearQuotedTextWindow()
  476. {
  477.   int    length;
  478.   
  479.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Allow the Quoted Text popup window to be edited */
  480.      TEXTSW_BROWSING, FALSE, NULL);
  481.  
  482.   length = (int)xv_get(QuoteMaker_quotedTextBaseWindow->quotedTextPane,    
  483.                TEXTSW_LENGTH);                    /* Get the number of characters currently in the... */
  484.                                     /* ...popup win. */
  485.   if (length > 0)
  486.     textsw_delete(QuoteMaker_quotedTextBaseWindow->quotedTextPane,  /* Erase any previously shown text in the Text... */
  487.           0, length);                        /* popup window. */
  488.   
  489.   textsw_reset(QuoteMaker_quotedTextBaseWindow->quotedTextPane,0,0); /* Pretend that the QTW was never modified */
  490.   
  491.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Allow the Quoted Text popup window to be edited */
  492.      TEXTSW_BROWSING, TRUE, NULL);
  493. }
  494.  
  495.  
  496. void
  497.   EnableQTWLocationChange()
  498. {
  499.   QTWLocationChangeEnabled = TRUE;
  500. }
  501.  
  502.  
  503. void
  504.   DisableQTWLocationChange()
  505. {
  506.   QTWLocationChangeEnabled = FALSE;
  507. }
  508.  
  509.  
  510. void
  511.   EnableQTWSizeChange()
  512. {
  513.   QTWSizeChangeEnabled = TRUE;
  514. }
  515.  
  516.  
  517.  
  518. void
  519.   DisableQTWSizeChange()
  520. {
  521.   QTWSizeChangeEnabled = FALSE;
  522. }
  523.  
  524.  
  525. void
  526.   EnableHideQTWAfterPlayingEdit()
  527. {
  528.   HideQTWAfterPlayingEdit = TRUE;
  529.   xv_set(QuoteMaker_baseWindow->HideQuoteWindowAfterPlayingEditSetting,
  530.      PANEL_VALUE, 1, NULL);
  531. }
  532.  
  533.  
  534. void
  535.   DisableHideQTWAfterPlayingEdit()
  536. {
  537.   HideQTWAfterPlayingEdit = FALSE;
  538.   xv_set(QuoteMaker_baseWindow->HideQuoteWindowAfterPlayingEditSetting,
  539.      PANEL_VALUE, 0, NULL);
  540. }
  541.  
  542.  
  543. void
  544.   PutInDefaultDuration()
  545. {
  546.   xv_set(QuoteMaker_baseWindow->DurationMinsTextField, PANEL_VALUE,
  547.      "0", NULL);
  548.   xv_set(QuoteMaker_baseWindow->DurationSecsTextField, PANEL_VALUE,
  549.      "2.0", NULL);
  550. }  
  551.  
  552.  
  553. void
  554.   InitQuotedTextWindow()
  555. {
  556.   (void) notify_interpose_event_func(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  557.                      QuotedTextWindowInterposer, NOTIFY_SAFE);
  558.  
  559.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  560.      FRAME_SHOW_HEADER, FALSE,                    /*  Hide the header and the footer of the quoted... */
  561.      FRAME_SHOW_FOOTER, FALSE,                    /*  ...text window.                                 */
  562.      NULL);
  563.  
  564. /**********
  565.   xv_set(xv_get(QuoteMaker_quotedTextBaseWindow->quotedTextPane,
  566.         WIN_VERTICAL_SCROLLBAR), XV_SHOW, FALSE, NULL);
  567.  
  568.   xv_destroy(xv_get(QuoteMaker_quotedTextBaseWindow->quotedTextPane,
  569.             WIN_VERTICAL_SCROLLBAR));
  570. ********/
  571.   
  572.   notify_interpose_destroy_func(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  573.                 DestroyQuoteWindow);
  574.  
  575.   EditTextFieldOrChoiceModified = FALSE;
  576.   EnableQTWLocationChange();                        /*  A notifier is set up to detect window resize... */
  577.   EnableQTWSizeChange();                        /*  ...and location change events.                  */
  578.   EnableHideQTWAfterPlayingEdit();
  579. }
  580.  
  581.  
  582. Notify_value
  583.   DestroyQuoteWindow(client, status)
  584. Notify_client client;
  585. Destroy_status status;
  586. {
  587.   if (status == DESTROY_CHECKING)
  588.   {
  589.     xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  590.        XV_SHOW, FALSE,
  591.        NULL);
  592.     notify_veto_destroy(client);
  593.   }
  594.  
  595.   return NOTIFY_DONE;
  596. }
  597.  
  598.  
  599. Notify_value
  600.   DestroyBaseWindow(client, status)
  601. Notify_client client;
  602. Destroy_status status;
  603. {
  604.   if (status == DESTROY_CHECKING)
  605.   {
  606.     if (unsavedChangesExist == YES)
  607.       GiveOneLastChanceToSave();
  608.   }
  609.   else if (status == DESTROY_CLEANUP)
  610.   {
  611.     xv_destroy_safe(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow);
  612.     SenderDisconnectFromPortMgr(sender,&(receiver->receivePort));        /* Tell the Port Manager "I'm outtahere" */
  613.     exit(0);
  614. /**
  615.   xv_destroy_safe(QuoteMaker_baseWindow->baseWindow);    
  616. **/  
  617.    
  618.     return notify_next_destroy_func(client, status);
  619.   }
  620.   return NOTIFY_DONE;
  621. }
  622.  
  623.  
  624.  
  625. /*
  626.  *  Right now the reason this function is so big is because
  627.  *  of the irregularity of the x interpose function.  For example,
  628.  *  If a window is resized, this function will receive 2 WIN_RESIZE
  629.  *  events and if the window is relocated, 1 WIN_RESIZE event
  630.  *  will be supplied.  Such inconsistency causes this function to 
  631.  *  be a product of "trial-and-error" --- and hidden bugs are 
  632.  *  expected.
  633.  */
  634. Notify_value
  635.   QuotedTextWindowInterposer(Frame        frame,
  636.                  Event*        event,
  637.                  Notify_arg        arg,
  638.                  Notify_event_type    type)
  639. {
  640.   int        currentSizeWidth;
  641.   int        currentSizeHeight;
  642.   static  Rect  tempRect;
  643.  
  644.   if (event_action(event) == WIN_RESIZE && event_id(event) != 31744)
  645.   {
  646.     if (xv_get(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow, XV_SHOW) == TRUE)
  647.     {
  648.       frame_get_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  649.              &tempRect);
  650.       currentSizeWidth = tempRect.r_width;
  651.       currentSizeHeight = tempRect.r_height;
  652.       sprintf(msg, "%d x %d", currentSizeWidth, currentSizeHeight);
  653.       xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->SizeMessage,
  654.          PANEL_LABEL_STRING, msg, NULL);
  655.       
  656.       if (currentSizeWidth != OldSizeWidth || currentSizeHeight != OldSizeHeight)
  657.       {
  658.     CheckIfEditModified(FALSE);
  659.       }
  660.       OldSizeWidth = currentSizeWidth;
  661.       OldSizeHeight = currentSizeHeight;
  662.       sprintf(msg, "%d x %d", tempRect.r_left, tempRect.r_top);
  663.       xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->LocationMessage,
  664.          PANEL_LABEL_STRING, msg, NULL);
  665.       if (tempRect.r_left != OldLocX || tempRect.r_top != OldLocY)
  666.       {
  667.     CheckIfEditModified(FALSE);
  668.       }
  669.       OldLocX = tempRect.r_left;
  670.       OldLocY = tempRect.r_top;
  671.     }
  672.   }
  673.   else if (!(event_action(event) == 31815 && event_id(event) == 31744))
  674.   {
  675.     if (xv_get(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow, XV_SHOW) == TRUE)
  676.     {
  677.       frame_get_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  678.              &tempRect);
  679.       sprintf(msg, "%d x %d", tempRect.r_left, tempRect.r_top);
  680.       xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->LocationMessage,
  681.          PANEL_LABEL_STRING, msg, NULL);
  682.       if (tempRect.r_left != OldLocX || tempRect.r_top != OldLocY)
  683.       {
  684.     CheckIfEditModified(FALSE);
  685.       }
  686.       else
  687.       {
  688.     if (!EditTextFieldOrChoiceModified)
  689.     {
  690.       ClearEditModified();
  691.     }
  692.       }
  693.       OldLocX = tempRect.r_left;
  694.       OldLocY = tempRect.r_top;
  695.     }                                    /*  ...resets the flag.                            */
  696.   }
  697.   
  698.   if (event_action(event) == 32536 && event_id(event) == 32536)
  699.   {
  700.     if (!EditTextFieldOrChoiceModified)
  701.     {
  702.       ClearEditModified();
  703.     }
  704.   }
  705.   return notify_next_event_func((Notify_client)frame,
  706.                 (Notify_event)event, arg, type);
  707. }
  708.  
  709.  
  710.  
  711. void
  712.   GetCurrentLocation(int* locX, int* locY)
  713. {
  714.   Rect  tempRect;
  715.   
  716.   frame_get_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  717.          &tempRect);
  718.   
  719.   *locX = tempRect.r_left;
  720.   *locY = tempRect.r_top;
  721. }
  722.  
  723.  
  724. void
  725.   SetCurrentLocation(int locX, int locY)
  726. {
  727.   static  Rect  tempRect;
  728.   
  729.   tempRect.r_left  = locX + FRAME_X_OFFSET;                /*  Some mysterious offsets to work-around the...   */
  730.   tempRect.r_top = locY + FRAME_Y_OFFSET;                /*  ..."shifting" when the window location is set.  */
  731.   
  732.   frame_set_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  733.          &tempRect);
  734. }
  735.  
  736.  
  737. void
  738.   GetCurrentSize(width, height)
  739. int   *width;
  740. int   *height;
  741. {
  742.   static  Rect  tempRect;
  743.  
  744.   frame_get_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  745.          &tempRect);
  746.   *width = tempRect.r_width;
  747.   *height = tempRect.r_height;
  748. }                                    /* end function GetCurrentSize */
  749.  
  750.  
  751. void
  752.   SetCurrentSize(int   width,
  753.          int   height)
  754. {
  755.   static  Rect  tempRect;
  756.  
  757.   tempRect.r_width = width;
  758.   tempRect.r_height = height;
  759.   frame_set_rect(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow,
  760.          &tempRect);
  761. }
  762.  
  763.   
  764. void
  765.   DisplayTextOnQuoteWindow()
  766. {
  767.   int        start;
  768.   int        end;
  769.   int        length;
  770.   int        count;
  771.   static  int    currentSelectedTextBufferLength = 1000;
  772.   static char*    selectedText = NULL;
  773.   char*        tempPointer;
  774.   char*        index();
  775.   
  776.   start = textWindowStart;                        /* Get start and end points for the selection.  */
  777.   end = textWindowEnd;
  778.   length = end - start + 1;                        /* Calculate size of text to be selected */
  779.   
  780.   if (!selectedText)
  781.   {
  782.     selectedText = malloc(1000);
  783.     currentSelectedTextBufferLength = 1000;
  784.   }
  785.   
  786.   if (currentSelectedTextBufferLength < length + 1)
  787.   {
  788.     currentSelectedTextBufferLength = length + 1;
  789.     selectedText = (char *) malloc(length + 1);                /* Allocate space for the text to be selected */
  790.   }
  791.     
  792.   if (!selectedText)
  793.   {
  794.     printf("malloc failure in Text pane event handler.\n");
  795.   }
  796.   
  797.   xv_get(QuoteMaker_textWindowPopup->mainTextPane,            /* Get the text to be selected */
  798.      TEXTSW_CONTENTS, start, selectedText, length);
  799.   selectedText[length] = '\0';                        /* Make sure selected text is NULL-terminated */
  800.   for (tempPointer = selectedText, count=0;                /* Go through selected text, looking for newlines... */
  801.        tempPointer;                            /* ...and replace each newline with a space. */
  802.        tempPointer = index(tempPointer, '\n'), count++)
  803.   {
  804.     if (tempPointer != selectedText)                    /* Is "tempPointer" pointing to start of the buffer? */
  805.       tempPointer[0] = ' ';                        /* No, must be pointing to a newline; replace it... */
  806.     /* ...with space. */
  807.     if (count > 100)                            /* If this loop has replaced a large number of ... */
  808.       break;                                /* ...lines, exit loop; chances are the end... */
  809.     /* ...won't be saved anyway. */
  810.   }
  811.   
  812.   currentFontSize = xv_get(QuoteMaker_QuoteWindowSpecificationsPopup->FontSizeTextField,
  813.                PANEL_VALUE);
  814.   
  815.   SetQuotedTextWindowFont(currentFontFamily,
  816.               currentFontStyle,
  817.               currentFontSize);
  818.   
  819.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Allow the Quoted Text popup window to be edited */
  820.      TEXTSW_BROWSING, FALSE, NULL);
  821.   
  822.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Put the selected text into the quoted Text... */
  823.      TEXTSW_CONTENTS, selectedText, NULL);                /* ...popup window */
  824.   
  825.   xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextPane,        /* Allow the Quoted Text popup window to be edited */
  826.      TEXTSW_BROWSING, TRUE, NULL);
  827.   
  828.   textsw_normalize_view(QuoteMaker_quotedTextBaseWindow->quotedTextPane,
  829.             0);                        /* Make sure quoted text shows up at top of... */
  830.   /* ...popup window. */
  831.   
  832. }  
  833.  
  834.  
  835.  
  836. void
  837.   UpdateButtonGlow()
  838. {
  839.   static short count = 0;
  840.   
  841.   if (count == 0)
  842.   {
  843.     count = 1;
  844.     if (Playing)
  845.     {
  846.       xv_set(QuoteMaker_baseWindow->PlayButton, PANEL_ITEM_COLOR, GreenColorIndex, NULL);
  847.     }
  848.   }
  849.   else
  850.   {
  851.     count = 0;
  852.     if (Playing)
  853.     {
  854.       xv_set(QuoteMaker_baseWindow->PlayButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  855.     }
  856.   }
  857. }
  858.  
  859.  
  860. void
  861.   CancelButtonGlow()
  862. {
  863.   xv_set(QuoteMaker_baseWindow->PlayButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  864.   xv_set(QuoteMaker_baseWindow->PauseButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  865. }
  866.